/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.anny.evaluate.service;

import java.text.DecimalFormat;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.anny.evaluate.entity.AnnyEvaluateConfig;
import com.jeeplus.modules.anny.evaluate.mapper.AnnyEvaluateConfigMapper;

/**
 * 积分配置Service
 * @author yxy
 * @version 2018-10-30
 */
@Service
@Transactional(readOnly = true)
public class AnnyEvaluateConfigService extends CrudService<AnnyEvaluateConfigMapper, AnnyEvaluateConfig> {

	public AnnyEvaluateConfig get(String id) {
		return super.get(id);
	}

	public List<AnnyEvaluateConfig> findList(AnnyEvaluateConfig annyEvaluateConfig) {
		return super.findList(annyEvaluateConfig);
	}

	public Page<AnnyEvaluateConfig> findPage(Page<AnnyEvaluateConfig> page, AnnyEvaluateConfig annyEvaluateConfig) {
		return super.findPage(page, annyEvaluateConfig);
	}


	/***
	 * 获得商品赠送积分
	 * @param price
	 */
	public int getEvaluate(double price){
		double proportion=1;
		AnnyEvaluateConfig config= super.findUniqueByProperty("config_type","0");
		if(config!=null) {
			proportion = Double.valueOf(config.getConfigValue());
		}
		int evaluate=(int)(price*proportion);
		//保留一位小数?
//		evaluate=((int)(evaluate*10))/10.0;
		return evaluate;
	}

	/**
	 * 获取签到积分配置
	 * @return 签到积分
	 */
	public int getQiandao(){
		AnnyEvaluateConfig config= super.findUniqueByProperty("config_type","2");
		return Integer.parseInt(config.getConfigValue());
	}
	@Transactional(readOnly = false)
	public void save(AnnyEvaluateConfig annyEvaluateConfig) {
		//如果已经存在配置就更新
		AnnyEvaluateConfig old=super.mapper.findUniqueByProperty("config_type",annyEvaluateConfig.getConfigType());
		if(old!=null){
			old.setConfigValue(annyEvaluateConfig.getConfigValue());
			old.setRemarks(annyEvaluateConfig.getRemarks());
			super.save(old);
			return;
		}
		super.save(annyEvaluateConfig);
	}

	@Transactional(readOnly = false)
	public void delete(AnnyEvaluateConfig annyEvaluateConfig) {
		super.mapper.delete(annyEvaluateConfig);
	}

}